
// 已加载数据下标集合
var loadedSet = new Set();

// 获取滚轮位置，加载当前位置之前的动画（包括当前位置）
function Init() {
    var scrollTop = document.documentElement.scrollTop || window.pageYOffset || document.body.scrollTop;
    var needload = (scrollTop + 740) / 740;
    callLocation(needload);

    // 注册页面滚动事件
    window.onscroll = function () {
        if (loadedSet.size < 6) {
            //获取实时页面位置
            var scrollTop = document.documentElement.scrollTop || window.pageYOffset || document.body.scrollTop;
            var needload = (scrollTop + 740) / 740;
            callLocation(needload);
        }
    }
}

// 传入当前位置，循环调用之前的动画
function callLocation(index) {
    for (var i = 1; i <= index; i++) {
        loadSectionAnime(i);
    }
}

// 加载动画
function loadSectionAnime(index) {
    if (loadedSet.has(index)) {
        return;
    }
    loadedSet.add(index, "complete");
    switch (index) {
        case 1:
        case 2:
        case 3:
        case 4:
        case 5:
        case 6:
            anime1(index);
            break;
        default:
            alert("动画加载错误！")
            break;
    }
    console.log("加载第" + index + "区域动画");
}



function anime1(index) {
    // 根据位置来加载section
    var section = $("#section" + index);
    // 显示容器节点
    $(section).find(".section-content").show();

    var anime_dyzh = $(section).find(".anime_dyzh")[0];
    transition.begin(anime_dyzh, [
        ["top", "100px", "260px", "0.3s", "ease-in-out"]
    ]);

    var anime_qycgdgj = $(section).find(".anime_qycgdgj")[0];
    transition.begin(anime_qycgdgj, [
        ["left", "-200px", "0", "0.3s", "ease-in-out"]
    ]);

    var anime_base = $(section).find(".anime_base")[0];
    transition.begin(anime_base, [
        ["transform", "scale(0.85,0.85)", "scale(1,1)", "0.7s", "ease-in-out"]
    ]);

    var anime_circuit = $(section).find(".anime_circuit")[0];
    transition.begin(anime_circuit, [
        ["opacity", "0.3", "1", "0.7s", "ease-in-out"]
    ]);

    var anime_lightBulb = $(section).find(".anime_lightBulb")[0];
    transition.begin(anime_lightBulb, [
        ["top", "60px", "174px", "0.5s", "ease-in-out"]
    ]);

    var anime_light = $(section).find(".anime_light")[0];
    transition.begin(anime_light, [
        ["opacity", "0", "1", "2s", "ease-in"]
    ]);

    var anime_three_arrow = $(section).find(".anime_three_arrow")[0];
    transition.begin(anime_three_arrow, [
        ["top", "177px", "127px", "0.7s", "ease-in-out"],
        ["opacity", "0.3", "1", "0.5s", "ease-in-out"]
    ]);

}